package com.xcity.tools.http.impl;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xcity.game.combat.attr.CombatAttribute;
import com.xcity.game.employee.template.EmployeeComboTemplate;
import com.xcity.tools.http.HttpService.SheetField;
import com.xcity.tools.http.XLS2JSONFilter;

public class EmployeeComboTemplateFilter implements XLS2JSONFilter<EmployeeComboTemplate> {

	@Override
	public Object doFilter(EmployeeComboTemplate template, String field, Method getter) throws Exception {
		if ("attributes".equals(field)) {
			CombatAttribute[] attrs = template.getAttributes();
			JSONArray wrapped = new JSONArray(attrs.length);
			for (CombatAttribute attr : attrs) {
				JSONObject val = new JSONObject(2, true);
				val.put("type", attr.getType());
				val.put("value", attr.format(attr.getValue()));
				wrapped.add(val);
			}
			return wrapped;
		}
		return getter.invoke(template);
	}

	@Override
	public List<SheetField> getFields() {
		List<SheetField> fields = new ArrayList<>();
		fields.add(new SheetField("id", "员工id"));
		fields.add(new SheetField("name", "羁绊名称"));
		fields.add(new SheetField("desc", "羁绊描述"));
		fields.add(new SheetField("viceIds", "副员工id"));
		fields.add(new SheetField("attributes", "属性提升"));
		return fields;
	}
	
	
}
